﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Faust.Andrew.MTG.Player
{
	/// <summary>
	/// Interaction logic for HandWindow.xaml
	/// </summary>
    public partial class HandWindow : Window, ICardListView
	{
        public bool RemoveManually
        {
            get
            {
                return cardListControl.RemoveManually;
            }
            set
            {
            	cardListControl.RemoveManually = value;
            }
        }

        public HandWindow()
		{
			this.InitializeComponent();
			
			// Insert code required on object creation below this point.
		}
        public static readonly DependencyProperty CardListProperty = DependencyProperty.Register("CardList", typeof(ObservableCollection<Shared.GameCard>), typeof(HandWindow), new UIPropertyMetadata(null, new PropertyChangedCallback(OnCardListChanged), new CoerceValueCallback(OnCoerceCardList)));

        private static object OnCoerceCardList(DependencyObject o, object value)
        {
            HandWindow handWindow = o as HandWindow;
            if (handWindow != null)
                return handWindow.OnCoerceCardList((ObservableCollection<Shared.GameCard>)value);
            else
                return value;
        }

        private static void OnCardListChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            HandWindow handWindow = o as HandWindow;
            if (handWindow != null)
                handWindow.OnCardListChanged((ObservableCollection<Shared.GameCard>)e.OldValue, (ObservableCollection<Shared.GameCard>)e.NewValue);

            handWindow.cardListControl.CardList = (ObservableCollection<Shared.GameCard>) e.NewValue;            
        }

        protected virtual ObservableCollection<Shared.GameCard> OnCoerceCardList(ObservableCollection<Shared.GameCard> value)
        {
            // TODO: Keep the proposed value within the desired range.
            return value;
        }

        protected virtual void OnCardListChanged(ObservableCollection<Shared.GameCard> oldValue, ObservableCollection<Shared.GameCard> newValue)
        {
            // TODO: Add your property changed side-effects. Descendants can override as well.
        }

        public ObservableCollection<Shared.GameCard> CardList
        {
            // IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!
            get
            {
                return (ObservableCollection<Shared.GameCard>)GetValue(CardListProperty);
            }
            set
            {
                SetValue(CardListProperty, value);
            }
        }

        public static readonly DependencyProperty PresenterProperty = DependencyProperty.Register("Presenter", typeof(GamePresenter), typeof(HandWindow), new UIPropertyMetadata(null, new PropertyChangedCallback(OnPresenterChanged), new CoerceValueCallback(OnCoercePresenter)));

        private static object OnCoercePresenter(DependencyObject o, object value)
        {
            HandWindow handWindow = o as HandWindow;
            if (handWindow != null)
                return handWindow.OnCoercePresenter((GamePresenter)value);
            else
                return value;
        }

        private static void OnPresenterChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            HandWindow handWindow = o as HandWindow;
            if (handWindow != null)
                handWindow.OnPresenterChanged((GamePresenter)e.OldValue, (GamePresenter)e.NewValue);

            handWindow.cardListControl.Presenter = (GamePresenter)e.NewValue;
        }

        protected virtual GamePresenter OnCoercePresenter(GamePresenter value)
        {
            // TODO: Keep the proposed value within the desired range.
            return value;
        }

        protected virtual void OnPresenterChanged(GamePresenter oldValue, GamePresenter newValue)
        {
            // TODO: Add your property changed side-effects. Descendants can override as well.
        }

        public GamePresenter Presenter
        {
            // IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!
            get
            {
                return (GamePresenter)GetValue(PresenterProperty);
            }
            set
            {
                SetValue(PresenterProperty, value);
            }
        }


        public double Zoom
        {
            get
            {
                return cardListControl.Zoom;
            }
            set
            {
                cardListControl.Zoom = value;
            }
        }

        //static HandWindow()
        //{
        //    PresenterProperty = DependencyProperty.Register("Presenter", typeof(GamePresenter), typeof(HandWindow));
        //    CardListProperty = DependencyProperty.Register("CardList", typeof(ObservableCollection<Shared.GameCard>), typeof(HandWindow));
        //}

        //static DependencyProperty CardListProperty;
        //public ObservableCollection<Shared.GameCard> CardList
        //{
        //    get
        //    {
        //        return (ObservableCollection<Shared.GameCard>) base.GetValue(CardListProperty);
        //    }

        //    set
        //    {
        //        base.SetValue(CardListProperty, value);
        //    }
        //}

        //static DependencyProperty PresenterProperty;
        //public GamePresenter Presenter
        //{
        //    get
        //    {
        //        return (GamePresenter)base.GetValue(PresenterProperty);
        //    }
        //    set
        //    {
        //        base.SetValue(PresenterProperty, value);
        //    }
        //}
	}
}